<!--
 * @description:
 * @author: cuicui
 * @Date: 2023-11-30 11:47:46
 * @LastEditTime: 2023-11-30 11:58:07
 * @LastEditors: cuicui
-->
<template>
  <a-modal
    title="添加曲线"
    :width="640"
    :visible="visible"
    :confirmLoading="loading"
    @ok="() => { $emit('ok') }"
    @cancel="() => { $emit('cancel') }"
  >
    <a-spin :spinning="loading">
      <a-form :form="form" v-bind="formLayout">
        <a-form-item label="站点">
          <a-select
            v-decorator="[
              'point',
              { rules: [{ required: true, message: '请选择站点!' }] },
            ]">
            <a-select-option value="0">站点1</a-select-option>
            <a-select-option value="1">站点2</a-select-option>
            <a-select-option value="2">站点3</a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item label="曲线名称">
          <a-select
            v-decorator="[
              'line_name',
              { rules: [{ required: true, message: '请选择曲线名称!' }] },
            ]">
            <a-select-option value="0">名称1</a-select-option>
            <a-select-option value="1">名称2</a-select-option>
            <a-select-option value="2">名称3</a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item label="曲线类型">
          <a-select
            v-decorator="[
              'line_type',
              { rules: [{ required: true, message: '请选择曲线类型!' }] },
            ]">
            <a-select-option value="0">类型1</a-select-option>
            <a-select-option value="1">类型2</a-select-option>
            <a-select-option value="2">类型3</a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item label="监控项">
          <a-select
            style="width: 120px"
            v-decorator="[
              'device',
              { rules: [{ required: true, message: '请选择设备' }] },
            ]">
            <a-select-option value="0">设备1</a-select-option>
            <a-select-option value="1">设备2</a-select-option>
            <a-select-option value="2">设备3</a-select-option>
          </a-select>

          <a-select
            style="width: 120px;margin-left: 10px;"
            v-decorator="[
              'pooint',
              { rules: [{ required: true, message: '请选择测点' }] },
            ]">
            <a-select-option value="0">测点1</a-select-option>
            <a-select-option value="1">测点2</a-select-option>
            <a-select-option value="2">测点3</a-select-option>
          </a-select>

          <a-select
            style="width: 120px;margin-left: 10px;"
            v-decorator="[
              'show_name',
              { rules: [{ required: true, message: '请选择显示名称' }] },
            ]">
            <a-select-option value="0">名称1</a-select-option>
            <a-select-option value="1">名称2</a-select-option>
            <a-select-option value="2">名称3</a-select-option>
          </a-select>
        </a-form-item>
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
  import pick from 'lodash.pick'

  // 表单字段
  const fields = ['sys-type', 'equipment_type', 'point_type']

  export default {
    props: {
      visible: {
        type: Boolean,
        required: true
      },
      loading: {
        type: Boolean,
        default: () => false
      },
      model: {
        type: Object,
        default: () => null
      }
    },
    data () {
      this.formLayout = {
        labelCol: {
          xs: { span: 24 },
          sm: { span: 3 }
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 21 }
        }
      }
      return {
        form: this.$form.createForm(this)
      }
    },
    created () {
      // 防止表单未注册
      fields.forEach(v => this.form.getFieldDecorator(v))

      // 当 model 发生改变时，为表单设置值
      this.$watch('model', () => {
        this.model && this.form.setFieldsValue(pick(this.model, fields))
      })
    }
  }
</script>
